相关资源
-
YouTube 视频: Introductory python tutorials for image processing - YouTube
-
Code associated with these tutorials can be downloaded from here:
-
参考书籍: 冈萨雷斯《数字图像处理》(第四版)
课程
Tutorial 01 - Why is it important for researchers to learn coding?
Tutorial 02 - What is digital image processing?
Tutorial 03 - Image processing in imageJ, ZEN, and APEER
- ImageJ: 科研人必备图像处理软件—ImageJ(安装篇)- 知乎 (zhihu.com)
- Zen lite: ZEISS ZEN lite
- APEER: APEER - automated image analysis
Tutorial 04 - Appreciating the simplicity of python
- 使用 Python 给图像添加 Sigma=2 的高斯模糊
from skimage import io, filters
from matplotlib import pyplot as plt
img = io.imread('images/Osteosarcoma_01_25Sigma_noise.tif') # 读取图片
gaussian_img = filters.gaussian(img, sigma=2) # 添加高斯模糊
plt.imshow(gaussian_img) # 显示图片
Tutorial 05 - How to install python using Anaconda
教你怎么装 Anaconda 和 Spyder..
Tutorial 06 - Understanding Anaconda Packages
教你怎么用 Anaconda ..
Tutorial 06b - Understanding python environments (using Anaconda)
教你怎么管理 Anaconda 环境..
Tutorial 07 - Getting familiar with spyder IDE
教你怎么用 Sypder..
Variable explorer 可以实时显示变量的类型和值?有点意思
Tutorial 08 - What are libraries in python
介绍了 Python 中库(library)的概念
Tutorial 09 - Top 5 python libraries for image analysis
PyPI · The Python Package Index
- Image processing
- scikit-image
- Opencv-python
- Data analysis
- numpy
- pandas
- Plotting & visualization
- matplotlib
- Other libraries worth mentioning
- scipy - scientfic and numerical tools, extension of numpy
- keras / tensorflow - deep learning
- seaborn and plotly - advanced, highly customizable plotting
- czifile, tifffile - many other libraries for specific tasks
Tutorial 10 - Writing your first lines of code in Python
教你怎么在 Spyder 里写 Python 代码, 算了, 我还是用 Jupyter 吧..
Tutorial 11 - Operators and basic math in Python
教你怎么用 Python 里的运算符和基本运算..
Tutorial 12 - What are Lists in Python
教你怎么用 Python 里的 list..
Tutorial 13 - What are Tuples in Python
教你怎么用 Python 里的 tuple..
就是个定义以后值不可变的 list..
Tutorial 14 - What are Dictionaries in Python
教你怎么用 Python 里的字典..
Dictionaries: a key and a value
- 定义字典的 3 种方式:
life_sciences = {'Botany': 'plants',
'Zoology': 'animals',
'Virology': 'viruses',
'Cell_biology': 'cells'}life_sciences = dict([('Botany', 'plants'),
('Zoology', 'animals'),
('Virology', 'viruses'),
('Cell_biology', 'cells')])life_sciences = dict(Botany = 'plants',
Zoology = 'animals',
Virology = 'viruses',
Cell_biology='cells')- 判断定义变量的类型
type(life_sciences)dict
- 查找
print('Zoology' in life_sciences)True
- 添加元素
life_sciences['Neuroscience'] = 'nervous_system'print(life_sciences){'Botany': 'plants', 'Zoology': 'animals', 'Virology': 'viruses', 'Cell_biology': 'cells', 'Neuroscience': 'nervous_system'}
- 删除元素
del life_sciences['Neuroscience']print(life_sciences){'Botany': 'plants', 'Zoology': 'animals', 'Virology': 'viruses', 'Cell_biology': 'cells'}
- 定义字典时只能用 tuple 作 key 而不是 list:
b = {(1, 0): 'a', (1, 1): 'b', (2, 2): 'c', (3, 2): 'd'}c = {[1, 0]: 'a', [1, 1]: 'b', [2, 2]: 'c', [3, 2]: 'd'}---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [12], in <cell line: 1>()
----> 1 c = {[1, 0]: 'a', [1, 1]: 'b', [2, 2]: 'c', [3, 2]: 'd'}
TypeError: unhashable type: 'list'
- 输出字典的 key
d = list(life_sciences.keys())
d['Botany', 'Zoology', 'Virology', 'Cell_biology']
- 输出字典的 value
e = list(life_sciences.values())
e['plants', 'animals', 'viruses', 'cells']
Tutorial 15 - What are numpy arrays in Python
教你了解 numpy
- numpy 与 list 的不同:
a = [1, 2, 3, 4, 5]
b = 2 * a
b[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
type(a)list
import numpy as np
c = np.array(a)
d = 2 * c
darray([ 2, 4, 6, 8, 10])
type(c)numpy.ndarray
c ** 2array([ 1, 4, 9, 16, 25], dtype=int32)
- 设置数据类型
import numpy as np
x = np.array([[1, 2], [3, 4]]) # 整型变量
y = np.array([[1, 2], [3, 4]], dtype=np.float64) # float
y/2array([[0.5, 1. ],
[1.5, 2. ]])
- 读取图像, 将图像存储为 numpy 矩阵
from skimage import io
img1 = io.imread('images/Osteosarcoma_01.tif')
type(img1)numpy.ndarray
- 图像(高, 宽, 通道数)
img1.shape(1104, 1376, 3)
- 创建图像
- 创建一个值全为 1, 大小和 img1 相同的图像
a = np.ones_like(img1)
a.shape(1104, 1376, 3)
- 切片
import numpy as np
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
np.shape(a)(3, 4)
aarray([[ 1, 2, 3, 4],
[ 5, 6, 7, 8],
[ 9, 10, 11, 12]])
a[:2]array([[1, 2, 3, 4],
[5, 6, 7, 8]])
a[:2, 1:3]array([[2, 3],
[6, 7]])
- 求和
np.sum(a, axis=0)array([15, 18, 21, 24])
np.sum(a, axis=1)array([10, 26, 42])
np.max(a)12
Tutorial 16 - Data types in python
- Data types:
| 类型 | 名称 |
|---|---|
| Text | str |
| Numbers | int, float, complex |
| Arrays(lists) | list, tuple, range |
| Mapping | dict |
| Boolean(True/False) | bool |
- For image processing using skimage:
| 变量名 | 值域 |
|---|---|
| uint8 | 0 to 255 |
| uint16 | 0 to 65535 |
| uint32 | 0 to 2^32-1 |
| float | -1 to 1 or 0 to 1 |
| int8 | -128 to 127 |
| int16 | -32768 to 32767 |
| int32 | -2^32 to 2^32-1 |
- 实例
from skimage import io, img_as_float
img = io.imread('images/Osteosarcoma_01.tif')
img2 = img_as_float(img)
img.max()255
img2.max()1.0
Tutorial 17 - if and else statements in python
教你怎么用 Python 里的 if-else..
Tutorial 18 - while loops in python
教你怎么用 Python 里的 while 循环..
Tutorial 19 - for loops in python
教你怎么用 Python 里的 for 循环..
通常用于遍历数组里的值
Tutorial 20 - Functions in Python
教你怎么用 Python 里的函数 ..
Tutorial 21 - Lambda Functions in Python
- 普通函数
def squared(x):
return x ** 2squared(4)16
- lambda 函数
a = lambda x: x ** 2
a(5)25
- 使用 lambda 函数
a = lambda x, y: 2 * x ** 2 + 3 * y
a(3, 5)33
- lambda 函数和普通函数混合使用
# S = ut + 1 / 2 a * t ** 2
def distance_eqn(u, a):
return lambda t: u * t + ((1 / 2) * a * t ** 2)dist = distance_eqn(5, 10)
dist(20)2100.0
distance_eqn(5, 10)(20)2100.0